unit Secure;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls;

type
  TFormSecure = class(TForm)
    LabelChar: TLabel;
    LabelPassword: TLabel;
    EditPassword: TEdit;
    fcImageForm1: TImage;
    BtnOK: TBitBtn;
    procedure EditPasswordKeyPress(Sender: TObject; var Key: Char);
    procedure BtnOKClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure EditPasswordChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    password: string;
    allowclose: boolean;
  end;

var
  FormSecure: TFormSecure;

implementation

{$R *.DFM}

procedure TFormSecure.FormCreate(Sender: TObject);
begin
  height:=150;
  width:=300;
  allowclose:=false;
end;

procedure TFormSecure.EditPasswordKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then begin
    key:=#0;
    BtnOK.click;
  end;
end;

procedure TFormSecure.BtnOKClick(Sender: TObject);
begin
  if EditPassword.text <> password then begin
    messagedlg('Password incorrect',mtwarning,[mbok],0);
    EditPassword.text:='';
    EditPassword.setfocus;
    exit;
  end;
  allowclose:=true;
  close;
end;

procedure TFormSecure.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  canclose:=allowclose;
end;

procedure TFormSecure.EditPasswordChange(Sender: TObject);
begin
  BtnOK.visible:=(EditPassword.text <> '');
end;

procedure TFormSecure.FormShow(Sender: TObject);
begin
  if not EditPassword.visible then begin
    BtnOK.show;
    BtnOK.setfocus;
  end
  else EditPassword.setfocus;
end;

end.
